Skip to content

Harden the backend for autoscaling - #1

Open
Mehulsri07 wants to merge 12 commits into
mainfrom
feat/horizon-hardening
Open

Mehulsri07 wants to merge 12 commits into
mainfrom
feat/horizon-hardening

Conversation

@Mehulsri07

Copy link
Copy Markdown
Owner

Summary

Makes the backend safe to autoscale, as the workload for Horizon Lab (Phase 1).

  • Shutdown: on SIGTERM, readiness fails first, then in-flight requests drain for up to 20 s. Server timeouts cut off slow clients.
  • Probes and work: /livez, /readyz, cancellable /slow and /cpu, and /work with a fixed, calibrated CPU cost.
  • Metrics: latency buckets around the 200 ms SLO, an in-flight gauge and build_info{version}. Injected faults are recorded in the metrics.
  • Faults: the memory-leak switch is on an internal admin port (:9091) only. A :bad image injects latency and errors.
  • Image: distroless, non-root, 19.2 MB. Compose no longer hard-codes the EC2 IP.
  • Capacity: scripts/capacity.py measured 40 rps per pod at 1 CPU / 128 MiB (results/capacity.json).

Test plan

  • go vet and go test -count=5 pass locally (without -race, which is unavailable on the dev machine)
  • Both images built; :bad fails about 10% of requests and adds 300 ms or more
  • Compose: /api/health, /api/info and /api/status return 200
  • go test -race and the image builds pass in CI (first run of this workflow)

Known gaps

  • Over-capacity runs on kind only reached about 86 rps, because k6 hit its user cap.
  • The calibration fix wasn't measured on a busy node.
  • Both get re-checked in Phase 5.

🤖 Generated with Claude Code

Mehulsri07 and others added 12 commits October 29, 2026 17:40
…gauge

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eady probes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ven fault injection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…leanup, CI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
burnCPU spun until a wall-clock deadline, so under contention a request
used less than WORK_CPU_MS of CPU and measured capacity depended on load.
It now runs a fixed number of xorshift iterations, calibrated once at
startup (and lazily via sync.Once for tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With /work now burning a calibrated 20ms of CPU per request, one
1 CPU / 128 MiB pod holds the 200ms p95 SLO up to 40 rps; at 50 rps
(100% of the CPU budget) the queue grows without bound.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt /work)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…config, name pod in admin

- Apply FaultMiddleware per route inside Instrument so injected 500s and
  latency reach http_requests_total and the duration histogram.
- Calibrate CPU as the fastest of 10 5ms windows; the single 50ms average
  read 0.23-0.40 of idle speed on a busy node, bringing back capacity drift.
- Treat NaN like an unparsable config value: default plus one warning.
- Include the pod hostname in POST /admin/leak and /admin/leak/stop responses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lt routing fixes

Still 40 rps per pod at the 200 ms p95 SLO.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant